import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:flutter_boost/flutter_boost_app.dart';
import 'package:ost_flutter_module/class/store/store_home_page.dart';

import 'flutter_boost_example/flutter_push_page.dart';
import 'flutter_boost_example/tab_0_page.dart';

// define logger
var logger = Logger();

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // 初始化 SpUtil, 用于存储数据
  await SpUtil.getInstance();
  runApp(MyApp()); //runApp(OSTApp());
}

class OSTApp extends StatefulWidget {
  OSTApp({Key key}) : super(key: key);

  @override
  _OSTAppState createState() => _OSTAppState();
}

class _OSTAppState extends State<OSTApp> {
  Map<String, FlutterBoostRouteFactory> routerMap = {
    'tab_0': (settings, uniqueId) => CupertinoPageRoute(
          builder: (contetx) => Tab0Page(),
          settings: settings,
        ),
    'flutter_push_page': (settings, uniqueId) => PageRouteBuilder(
          pageBuilder: (_, __, ___) => FlutterPushPage(
            arguments: settings.arguments,
            uniqueId: uniqueId,
          ),
          settings: settings,
        ),
  };

  Route<dynamic> routeFactory(RouteSettings settings, String uniqueId) {
    FlutterBoostRouteFactory func = routerMap[settings.name];
    if (func == null) {
      return null;
    }
    return func(settings, uniqueId);
  }

  @override
  Widget build(BuildContext context) {
    return FlutterBoostApp(routeFactory);
  }
}

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: StoreHomePage());
  }
}
